package com.ssm.gbq.service.impl;

import com.ssm.gbq.dao.OrderDao;
import com.ssm.gbq.model.Order;
import com.ssm.gbq.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderDao orderDao;

    /**
     * 插入订单数据
     * @param order 订单数据
     * @return 返回受影响的行数
     */
    public void insert(Order order) {

        order.setCreateTime(new Date());
        order.setModifitedTime(new Date());

        Integer rows = orderDao.insert(order);

        if (rows == null) {
            return;
        }

    }

    /**
     * 根据id删除订单数据
     * @param id 订单id
     * @return 返回受影响的行数
     */
    public void deleteById(Integer id) {
        Integer rows = orderDao.deleteById(id);
        if(rows==null){
            return;
        }
    }

    /**
     * 根据订单id修改订单数据
     * @param order
     */
    public void updateById(Order order) {
        order.setModifitedTime(new Date());
        orderDao.updateById(order);
    }



    /**
     * 获取订单列表
     * @return 所有的订单集合
     */
    public List<Order> getAll() {
        return orderDao.findAll();
    }

    public List<Order> getByLimitPage(Integer currentPage, Integer pageSize) {
        List<Order> list = orderDao.openOrderTable(currentPage,pageSize);

        return list;
    }

    public List<Order> getByName(String name) {
        name = "%"+name+"%";
        return orderDao.selectByName(name);
    }
}
